{include file="public/header" /}
<form class="layui-form">
	<div class="layui-form-item">
		<label class="layui-form-label">标题</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="title" placeholder="请输入标题">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">URL</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="url" placeholder="请输入跳转地址">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">图片</label>
		<div class="layui-input-inline">
			<button type="button" class="layui-btn" id="up">上传图片</button>
		</div>
		<div class="layui-form-mid layui-word-aux">支持png,jpg,gif</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">图片预览</label>
		<div class="layui-input-block">
			<div class="layui-upload-list" id="demo" style="width:90%;float:left;"></div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">排序</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="sort" placeholder="值越大、越靠前">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">状态</label>
		<div class="layui-input-block">
			<input type="radio" name="status" value="1" title="开启" checked="">
			<input type="radio" name="status" value="0" title="禁用">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">位置</label>
		<div class="layui-input-block">
			<select name="position">
				<option value="1">首页banner图</option>
			</select>
		</div>
	</div>
</form>
<div class="layui-form-item" style="margin-top:10px;">
	<div class="layui-input-block">
		<button type="button" class="layui-btn" onclick="save()">保存</button>
	</div>
</div>
<script type="text/javascript">
	layui.use(['layer','form','upload'],function(){
		var form = layui.form;
		layer = layui.layer;
		$ = layui.jquery;

		upload = layui.upload;
		upload.render({
			elem: "#up",
			url: "{$config['admin_route']}index/upload_img",
			done: function(res,title){
				if(res.code > 0){
					return layer.msg("上传失败，"+res.msg);
				}else{
					$("#demo").html('<div class="upload_pic_li" style="position:relative; width:100px; float:left; margin:0 10px 10px 0"><img style="width:100px;height:100px;" src="'+ res.url +'" class="layui-upload-img" onmouseover="show_img(this)" onmouseleave="hide_img()"><input type="hidden" name="pic" value="'+res.data+'"/><a class="close-img" href="javascript:;" onclick="deleteImage(\''+res.data+'\',this);return false;"></a></div>');
				}
			}
		});
	});

	function save(){
		$.post("{$config['admin_route']}oyk/ad_add",$('form').serialize(),function(res){
			if(res.code>0){
				layer.msg(res.msg,{'icon':2});
			}else{
				layer.msg(res.msg,{'icon':1});
				setTimeout(function(){parent.window.location.reload();},1000);
			}
		},'json');
	}
</script>
{include file="public/tail" /}